<template>
  <div v-loading="loading">
    <queryHead v-if="head" :explain="explain" :result="msg" :time="time" :price="price" @query="query"/>
    <div v-if="lock" style="background-color: #fafafa;padding: 5px;border-radius: 5px">
      <i class="el-icon-s-check" style="margin-top: 10px">
        <label>实名认证({{ jcxx.smrzMsg }}) | 手机三要素信息({{ jcxx.sjsysMsg }}) | 在网时长({{ jcxx.sjzwsjMsg }})</label>
      </i>
      <table id="sfhy">
        <thead>
        <tr>
          <th>实名认证</th>
          <th colspan="4">运营商手机号三要素</th>
          <th>手机号在网时长(月)</th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <td rowspan="3">姓名与身份证号
            <label>
              {{ jcxx.smrz.final_valid_result == '0' ? '一致' : '不一致' }}
            </label>
          </td>
          <td>服务商</td>
          <td>服务商代码</td>
          <td>归属省份</td>
          <td>归属城市</td>
          <td rowspan="3">
            <label>
              {{ jcxx.sjzwsj.time }}
            </label>
          </td>
        </tr>
        <tr>
          <td>{{ jcxx.sjsys.attribute }}</td>
          <td>{{ jcxx.sjsys.attribute_en }}</td>
          <td>{{ jcxx.sjsys.province }}</td>
          <td>{{ jcxx.sjsys.city }}</td>
        </tr>
        <tr>
          <td colspan="4">
            <label>
              {{
                jcxx.sjsys.checkResult == '0' ? '手机号与身份证号，姓名一致' : jcxx.sjsys.checkResult == '1' ? '手机号与身份证号或姓名不一致' : ''
              }}
            </label>
          </td>
        </tr>
        </tbody>
      </table>
      <div class="text-center result mb-2">
        (姓名，身份证号，手机号码{{
          jcxx.smrz.final_valid_result == '0' && jcxx.sjsys.checkResult == '0' ? '均匹配' : '匹配异常'
        }})
      </div>
    </div>
  </div>
</template>

<script>
  import queryHead from "@/views/components/queryHead.vue"
  import {queryData, queryRecord, updateQuery} from "@/api/system/query";
  export default {
    components: {queryHead},
    name: "syshc",
    props: {
      queryData: {
        required: true,
        type: Object
      },
      price: {
        default: null,
        type: Number
      },
      priceType: {
        default: null,
        type: Boolean
      },
      explain: {
        default: null,
        type: String
      },
      head: {
        default: true,
        type: Boolean
      }
    },
    data() {
      return {
        loading: false,
        lock: false,

        msg: undefined,
        time: undefined,

        jcxx: {
          smrzMsg: '',
          sjsysMsg: '',
          sjzwsjMsg: '',
          smrz: {
            final_valid_result: ''
          },
          sjsys: {
            attribute: '',
            attribute_en: '',
            checkResult: '',
            city: '',
            province: ''
          },
          sjzwsj: {
            time: ''
          }
        }
      }
    },
    mounted() {
      this.loading = true
      queryRecord(this.queryData).then(response => {
        this.disResponse(response)
      })
    },
    methods: {
      query() {
        this.loading = true
        queryData(this.queryData).then(response => {
          this.disResponse(response)
        });
      },
      disResponse(response) {
        if (!response.time) {
          this.loading = false
          return
        }
        this.time = response.time
        const info = JSON.parse(response.info)

        console.log('---info---',info)
        // smrz
        let smrz = info.smrz
        this.jcxx.smrzMsg = smrz.retmsg
        if (smrz.retcode == '000000') {
          this.jcxx.smrz.final_valid_result = smrz.retdata.final_valid_result
        } else {
          this.$modal.msgWarning('实名认证查询失败，原因：' + smrz.retmsg)
        }
        // sys
        let sys = info.sys
        this.jcxx.sjsysMsg = sys.retmsg
        if (sys.retcode == '000000') {
          this.jcxx.sjsys = sys.retdata
          let checkResult = sys.retdata.checkResult
          updateQuery({
            queryId: this.queryData.queryId,
            threeElmentAuth: checkResult == '0' ? '三要素一致' : checkResult == '1' ? '手机号与身份证号或姓名不一致' : ''
          })
        } else {
          this.$modal.msgWarning('手机三要素查询失败，原因：' + sys.retmsg);
        }
        // zwsc
        let zwsc = info.zwsc
        this.jcxx.sjzwsjMsg = zwsc.retmsg
        const retcode = zwsc.retcode
        if (retcode == '000000' || retcode == '000001' || retcode == '000002' || retcode == '000003' || retcode == '100000') {
          const inTime = zwsc.retdata.inTime
          this.jcxx.sjzwsj.time = '0' == inTime ? '[0,3)' : '3' == inTime ? '[3,6) ' : '6' == inTime ? '[6,12)' : '12' == inTime ? '[12,24)' : '24' == inTime ? '[24,+) ' : '99' == inTime ? '手机号已离网/新入网/手机状态异常' : '-1' == inTime ? '查无记录' : inTime
        } else {
          this.$modal.msg('在网时长查询失败，原因：' + zwsc.retmsg)
        }
        this.msg = "查询完成"
        this.lock = true
        this.loading = false
      }
    }
  }
</script>

<style scoped>

  #sfhy {
    border-collapse: collapse;
    margin: 0 auto;
    width: 100%;
  }

  #sfhy th, td {
    text-align: center;
    border: 1px solid #ccc;
    padding: 20px 0px;
  }

  th {
    background-color: #fafafa;
  }
</style>



